<?php


abstract class BaseUsuario extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $cp_usuario;


	
	protected $cf_nivel;


	
	protected $cf_trabajador;


	
	protected $usuario;


	
	protected $login;


	
	protected $clave;


	
	protected $chequeado;


	
	protected $estatus;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getCpUsuario()
	{

		return $this->cp_usuario;
	}

	
	public function getCfNivel()
	{

		return $this->cf_nivel;
	}

	
	public function getCfTrabajador()
	{

		return $this->cf_trabajador;
	}

	
	public function getUsuario()
	{

		return $this->usuario;
	}

	
	public function getLogin()
	{

		return $this->login;
	}

	
	public function getClave()
	{

		return $this->clave;
	}

	
	public function getChequeado()
	{

		return $this->chequeado;
	}

	
	public function getEstatus()
	{

		return $this->estatus;
	}

	
	public function setCpUsuario($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cp_usuario !== $v) {
			$this->cp_usuario = $v;
			$this->modifiedColumns[] = UsuarioPeer::CP_USUARIO;
		}

	} 
	
	public function setCfNivel($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_nivel !== $v) {
			$this->cf_nivel = $v;
			$this->modifiedColumns[] = UsuarioPeer::CF_NIVEL;
		}

	} 
	
	public function setCfTrabajador($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_trabajador !== $v) {
			$this->cf_trabajador = $v;
			$this->modifiedColumns[] = UsuarioPeer::CF_TRABAJADOR;
		}

	} 
	
	public function setUsuario($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->usuario !== $v) {
			$this->usuario = $v;
			$this->modifiedColumns[] = UsuarioPeer::USUARIO;
		}

	} 
	
	public function setLogin($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->login !== $v) {
			$this->login = $v;
			$this->modifiedColumns[] = UsuarioPeer::LOGIN;
		}

	} 
	
	public function setClave($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->clave !== $v) {
			$this->clave = $v;
			$this->modifiedColumns[] = UsuarioPeer::CLAVE;
		}

	} 
	
	public function setChequeado($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->chequeado !== $v) {
			$this->chequeado = $v;
			$this->modifiedColumns[] = UsuarioPeer::CHEQUEADO;
		}

	} 
	
	public function setEstatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->estatus !== $v) {
			$this->estatus = $v;
			$this->modifiedColumns[] = UsuarioPeer::ESTATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->cp_usuario = $rs->getString($startcol + 0);

			$this->cf_nivel = $rs->getString($startcol + 1);

			$this->cf_trabajador = $rs->getString($startcol + 2);

			$this->usuario = $rs->getString($startcol + 3);

			$this->login = $rs->getString($startcol + 4);

			$this->clave = $rs->getString($startcol + 5);

			$this->chequeado = $rs->getString($startcol + 6);

			$this->estatus = $rs->getString($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Usuario object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UsuarioPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			UsuarioPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(UsuarioPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = UsuarioPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setCpUsuario($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += UsuarioPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = UsuarioPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = UsuarioPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCpUsuario();
				break;
			case 1:
				return $this->getCfNivel();
				break;
			case 2:
				return $this->getCfTrabajador();
				break;
			case 3:
				return $this->getUsuario();
				break;
			case 4:
				return $this->getLogin();
				break;
			case 5:
				return $this->getClave();
				break;
			case 6:
				return $this->getChequeado();
				break;
			case 7:
				return $this->getEstatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = UsuarioPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCpUsuario(),
			$keys[1] => $this->getCfNivel(),
			$keys[2] => $this->getCfTrabajador(),
			$keys[3] => $this->getUsuario(),
			$keys[4] => $this->getLogin(),
			$keys[5] => $this->getClave(),
			$keys[6] => $this->getChequeado(),
			$keys[7] => $this->getEstatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = UsuarioPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCpUsuario($value);
				break;
			case 1:
				$this->setCfNivel($value);
				break;
			case 2:
				$this->setCfTrabajador($value);
				break;
			case 3:
				$this->setUsuario($value);
				break;
			case 4:
				$this->setLogin($value);
				break;
			case 5:
				$this->setClave($value);
				break;
			case 6:
				$this->setChequeado($value);
				break;
			case 7:
				$this->setEstatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = UsuarioPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setCpUsuario($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCfNivel($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCfTrabajador($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setUsuario($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setLogin($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setClave($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setChequeado($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setEstatus($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(UsuarioPeer::DATABASE_NAME);

		if ($this->isColumnModified(UsuarioPeer::CP_USUARIO)) $criteria->add(UsuarioPeer::CP_USUARIO, $this->cp_usuario);
		if ($this->isColumnModified(UsuarioPeer::CF_NIVEL)) $criteria->add(UsuarioPeer::CF_NIVEL, $this->cf_nivel);
		if ($this->isColumnModified(UsuarioPeer::CF_TRABAJADOR)) $criteria->add(UsuarioPeer::CF_TRABAJADOR, $this->cf_trabajador);
		if ($this->isColumnModified(UsuarioPeer::USUARIO)) $criteria->add(UsuarioPeer::USUARIO, $this->usuario);
		if ($this->isColumnModified(UsuarioPeer::LOGIN)) $criteria->add(UsuarioPeer::LOGIN, $this->login);
		if ($this->isColumnModified(UsuarioPeer::CLAVE)) $criteria->add(UsuarioPeer::CLAVE, $this->clave);
		if ($this->isColumnModified(UsuarioPeer::CHEQUEADO)) $criteria->add(UsuarioPeer::CHEQUEADO, $this->chequeado);
		if ($this->isColumnModified(UsuarioPeer::ESTATUS)) $criteria->add(UsuarioPeer::ESTATUS, $this->estatus);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(UsuarioPeer::DATABASE_NAME);

		$criteria->add(UsuarioPeer::CP_USUARIO, $this->cp_usuario);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getCpUsuario();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setCpUsuario($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCfNivel($this->cf_nivel);

		$copyObj->setCfTrabajador($this->cf_trabajador);

		$copyObj->setUsuario($this->usuario);

		$copyObj->setLogin($this->login);

		$copyObj->setClave($this->clave);

		$copyObj->setChequeado($this->chequeado);

		$copyObj->setEstatus($this->estatus);


		$copyObj->setNew(true);

		$copyObj->setCpUsuario(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new UsuarioPeer();
		}
		return self::$peer;
	}

} 